package com.mis.horario;


import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.BaseAdapter;

public class AdapterMateria extends BaseAdapter  {
	
	private List<Materia> Materias;
	private static LayoutInflater inflater = null;
	

	public AdapterMateria(Context context, List<Materia> Materias) {
	     	this.Materias = Materias;
	        inflater = LayoutInflater.from(context);	        
   }
	
	public int getCount() {		
		return Materias.size();		
	}

	public Object getItem(int position) {		
		return Materias.get(position);
	}

	public long getItemId(int position) {		
		return Materias.get(position).getId();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		
		if (convertView == null){
			
			vi = inflater.inflate(R.layout.materia, null);
			ViewHolder holder = new ViewHolder();
			
			holder.idMateria = (TextView) vi.findViewById(R.id.idMateria);
			holder.nombre = (TextView) vi.findViewById(R.id.nombre);
			holder.profesor = (TextView) vi.findViewById(R.id.profesor);
			//holder.horario = (TextView) vi.findViewById(R.id.horario);
			vi.setTag(holder);
		}
		
		Materia materia = Materias.get(position);
		
		if (materia != null){
			
			ViewHolder holder = (ViewHolder)vi.getTag();
			
			
			holder.idMateria.setText(String.valueOf(materia.getId()));
			holder.nombre.setText(materia.getNombre());
			holder.profesor.setText(materia.getProfesor());
			//holder.horario.setText(materia.getHorario());
			
		}			
       
		return vi;
	}
	
    static class ViewHolder {    	
    	
    	private TextView idMateria;    	
        private TextView nombre;
        private TextView profesor;
        //private TextView horario;
        
    }

}
